﻿using System;
using System.Collections.Generic;
using System.Collections;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls.WebParts;
using System.Data;
using System.Data.SqlClient;

public partial class manage : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        loginname.Text=Session["se1"].ToString();
        if (Session["Role"].ToString() == "2")
        {
            Panel1.Visible = true;
            Panel2.Visible = true;
            Panel3.Visible = true;
        }
        else
        {
            Panel1.Visible = false;
            Panel2.Visible = false;
            Panel3.Visible = false;
        }
        if (!IsPostBack)
        {
            Bind();
        }
    }
    private void Bind()
    {
        myGrid.DataSource = new Xqsys.BLL.Users().GetAllList();
        myGrid.DataKeyNames = new String[] { "userID" };
        myGrid.DataBind();
    }
    protected void myGrid_RowEditing(object sender, GridViewEditEventArgs e)
    {
        this.myGrid.EditIndex = e.NewEditIndex;
        Bind();
    }
    protected void myGrid_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        Xqsys.MODEL.Users user = new Xqsys.MODEL.Users();
        user.UserID = Convert.ToInt32(myGrid.DataKeys[e.RowIndex].Value.ToString().Trim());
        if (new Xqsys.BLL.Users().DeleteUser(user))
        {
            Label1.Text = "<script>alert('删除成功')</script>";
            Response.Redirect(Request.Url.AbsoluteUri);
        }
        else
        {
            Label1.Text = "<script>alert('删除失败')</script>";
        }
    }
    protected void myGrid_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        Xqsys.MODEL.Users user=new Xqsys.MODEL.Users();
        user.UserID = Convert.ToInt32(myGrid.DataKeys[e.RowIndex].Value.ToString().Trim());
        user.Role = Convert.ToInt32(((TextBox)myGrid.Rows[e.RowIndex].Cells[2].Controls[0]).Text.ToString().Trim());
        user.Mark =Convert.ToInt32(((TextBox)myGrid.Rows[e.RowIndex].Cells[3].Controls[0]).Text.ToString().Trim());
        user.Appraise =Convert.ToInt32(((TextBox)myGrid.Rows[e.RowIndex].Cells[10].Controls[0]).Text.ToString().Trim());
        if (new Xqsys.BLL.Users().UpDating(user))
        {
            Label1.Text = "<script>alert('更新成功!')</script>";
        }
        else
        {
            Label1.Text = "<script>alert('更新失败!')</script>";
        }
        myGrid.EditIndex = -1;
        Bind();
    }
    protected void myGrid_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
    {
        myGrid.EditIndex = -1;
        Bind();
    }
    protected void zhuxiao_Click(object sender, EventArgs e)
    {
        Session.Clear();
    }
}